﻿using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using CodeContrib.Web.Routing;

namespace CodeContrib.Web.Mvc.Routing
{
	public class TenantRouteConstraint : IRouteConstraint
	{
		public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
		{
			if (values[parameterName]
			    == UrlParameter.Optional)
			{
				return true;
			}

			return (httpContext.Items[TenantRoute.HttpContextKey] != null);
		}
	}
}